package com.ruoyi.common.utils;

/**
 * @Author: mokj3
 * @CreateTime: 2023-08-07 14:30
 * @Description: 整数转32进制
 */
public class IntegerToBase32 {
    public static void main(String[] args) {
        int number = 31;
        String base32 = convertToBase32(number);
        System.out.println("Base32 representation: " + base32);
    }

    public static String convertToBase32(int number) {
        if (number == 0) {
            return "0";
        }

        StringBuilder sb = new StringBuilder();
        while (number != 0) {
            int remainder = number % 32;
            char digit = getBase32Digit(remainder);
            sb.append(digit);
            number /= 32;
        }

        return sb.reverse().toString();
    }

    private static char getBase32Digit(int digit) {
        if (digit >= 0 && digit <= 9) {
            return (char) ('0' + digit);
        } else {
            return (char) ('A' + digit - 10);
        }
    }
}

